package com.bis.ymyy.controller;

import com.bis.ymyy.common.utils.InoculationSiteInfo;
import com.bis.ymyy.common.utils.Result;
import com.bis.ymyy.entity.InoculationSite;
import com.bis.ymyy.service.InoculationSiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inoculationSite")
@Api(tags = "/接种地点相关接口")
public class InoculationSiteController {
    @Autowired(required = false)
    private InoculationSiteService inoculationSiteService;

    @ApiOperation("/查询所有接种点")
    @GetMapping("/findAllSite")
    public Result<List> findAllSite(){
        Result<List> result = new Result<>();
        List<InoculationSite> inoculationSiteList = inoculationSiteService.findAllSite();
        result.setCode(200);
        result.setMsg("成功");
        result.setSuccess(true);
        result.setData(inoculationSiteList);
        return result;
    }

    @ApiOperation("/根据省或市查询具体接种点")
    @PostMapping("/findBySiteInfo")
    public Result<List> findBySiteInfo(@RequestBody InoculationSiteInfo siteInfo){
        Result<List> result = new Result<>();
        if (siteInfo == null){
            result.setMsg("参数为空");
            result.setCode(400);
            result.setSuccess(false);
        } else {
            if ( siteInfo.getCity().equals("") ) {
                List<InoculationSite> inoculationSiteList =
                        inoculationSiteService.findByProvince(siteInfo.getProvince());
                result.setData(inoculationSiteList);
                result.setCode(200);
                result.setSuccess(true);
                result.setMsg("成功");
            } else {
                List<InoculationSite> inoculationSiteList =
                        inoculationSiteService.findByProvinceAndCity(siteInfo);
                result.setCode(200);
                result.setSuccess(true);
                result.setMsg("成功");
                result.setData(inoculationSiteList);
            }
        }
        return result;
    }
}
